package javagamecontroller.activities.controllers;

import com.javagamecontroller.R;
import com.javagamecontroller.R.string;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;

/**
 * 
 * @author Lance
 *
 */
@TargetApi(11)
public class PauseDialogFragment extends DialogFragment{
    // Use this instance of the interface to deliver action events
    IPauseDialogListener dialogListener;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage(R.string.pause_dialog)
               .setPositiveButton(R.string.pause_pos_button, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       dialogListener.onDialogPositiveClick(PauseDialogFragment.this);
                   }
               })
               .setNegativeButton(R.string.pause_neg_button, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) {
                       dialogListener.onDialogNegativeClick(PauseDialogFragment.this);
                   }
               });
        // Create the AlertDialog object and return it
        return builder.create();
    }
    

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        // Verify that the host activity implements the callback interface
        try {
            // Instantiate the NoticeDialogListener so we can send events to the host
            dialogListener = (IPauseDialogListener) activity;
        } catch (ClassCastException e) {
            // The activity doesn't implement the interface, throw exception
            throw new ClassCastException(activity.toString()
                    + " must implement IPauseDialogListener");
        }
    }
    
}
